﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickApp.DbInterface;
using QuickApp.DbInterface.Helpers;

namespace QuickApp.SqlSilver
{
    public class SqlServerDatabase : QADbDatabase
    {
        public SqlServerDatabase(string name,string displayName, QADbManager dataManager)
            : base(name, displayName, dataManager)
        {

        }
        //TODO : Make enum with central key/string dictionary
        public override string GetSQLDataType()
        {
            return "SQL Server";
        }

        protected override List<QADbTable> loadTables()
        {
            base.tables = new List<QADbTable>();
            foreach (DataRow dr in dataManager.SelectTable("SELECT TABLE_SCHEMA,TABLE_NAME FROM " + Name + ".INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY 1,2").Rows)
            {
                string displayName = dr[0].ToString() + "." + dr[1].ToString();
                string name = dr[1].ToString().EncloseInSquareBrackets();
                    dr[1].ToString().EncloseInSquareBrackets();
                tables.Add(new SqlServerTable(name, displayName, dataManager, this));
            }
                
            return tables;
        }
    }
}
